﻿using System;
using System.ComponentModel;
using Rio.Framework.Localisation;

namespace Rio.Framework.Pages.Models
{
    public class LoginValidator : INotifyPropertyChanged
    {
        //Message error
        private string m_sMsgLoginRequired;

        #region Properties
        private string m_sLogin;
        private string m_sPassword;

        public string Login
        {
            get { return m_sLogin; }
            set
            {
                //Validation rule 1
                if (value == String.Empty)
                {
                    throw new Exception(m_sMsgLoginRequired);
                }

                m_sLogin = value;
                OnNotifyPropertyChanged("Login");
            }
        }

        public string Password
        {
            get { return m_sPassword; }
            set
            {
                m_sPassword = value;
                OnNotifyPropertyChanged("Password");
                m_sPassword = value;
            }
        }
        #endregion

        public LoginValidator()
        {
            InitLabel();
        }

        /// <summary>
        /// Translation
        /// </summary>
        public void InitLabel()
        {
            m_sMsgLoginRequired = Resx.GetLabel(ResxLogin.VALIDATOR_LOGIN_REQUIRED);
            Resx.GetLabel(ResxLogin.VALIDATOR_PASSWORD_REQUIRED);
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnNotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion
    }
}
